package com.example.smartcity_40.lawyer.apter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.smartcity_40.R;
import com.example.smartcity_40.lawyer.bean.UserevaluateBean;
import com.example.smartcity_40.tool.Tool;

import java.util.List;

public class UserevaluateApter extends RecyclerView.Adapter<UserevaluateApter.Myhot> {

    private Context context;
    private List<UserevaluateBean.RowsBean> list;

    public UserevaluateApter(Context context) {
        this.context = context;
    }

    public void setDate(List<UserevaluateBean.RowsBean> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public UserevaluateApter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.l_item_userevaluate, null);
        return new UserevaluateApter.Myhot(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull UserevaluateApter.Myhot holder, int position) {
        try {
            String imgUrl = list.get(position).getFromUserAvatar();

            Glide.with(context).load(Tool.url + imgUrl)
                    .error(R.drawable.waimai)
                    .into(holder.fromUserAvatar);


            String serviceName = list.get(position).getFromUserName();
            if (!TextUtils.isEmpty(serviceName)) {
                holder.fromUserName.setText(serviceName);
            }

            String evaluateContent = list.get(position).getEvaluateContent();
            if (!TextUtils.isEmpty(evaluateContent)) {
                holder.evaluateContent.setText(evaluateContent);
            }

            String createTime = list.get(position).getCreateTime();
            if (!TextUtils.isEmpty(createTime)) {
                int index = createTime.indexOf("T");
                holder.createTime.setText(createTime.substring(0,index));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class Myhot extends RecyclerView.ViewHolder {

        private final TextView fromUserName;
        private final TextView evaluateContent;
        private final ImageView fromUserAvatar;
        private final TextView createTime;
        private final RelativeLayout relayout;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            fromUserAvatar = itemView.findViewById(R.id.fromUserAvatar);
            fromUserName = itemView.findViewById(R.id.fromUserName);
            evaluateContent = itemView.findViewById(R.id.evaluateContent);
            createTime = itemView.findViewById(R.id.createTime);
            relayout = itemView.findViewById(R.id.relayout);
        }
    }
}

/**
 * 点击用户评价，展示
 * 评价列表，内容包括用户头像、昵称、评价时间、评价内容、点赞按
 * 钮和点赞数量，点击点赞按钮切换点赞状态；底部显示免费咨询按钮
 */



